package com.sporadic.desk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sporadic.desk.dao.MenuDao;
import com.sporadic.desk.pojo.Menu;
import com.sporadic.desk.service.MenuService;
import dto.MenuDTO;
import org.apache.ibatis.reflection.ArrayUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @program: sporadic
 * @description:
 * @author: LHD   QQ:1727865856
 * @create: 2019-10-22 09:33
 **/
@Service
public class MenuServiceImpl extends ServiceImpl<MenuDao, Menu> implements MenuService {

    @Override
    public List<Integer> queryTab(Integer menuId, Integer mid) {
        Menu menu = super.getOne(
                new QueryWrapper<Menu>()
                        .eq("menu_id", menuId)
                        .eq("menu_merachatId", mid));
        //将不为空的tab封装到list中
        List<Integer> list = new ArrayList<>();
        if (menu != null) {
            if (menu.getTab1() != null) list.add(menu.getTab1());
            if (menu.getTab2() != null) list.add(menu.getTab2());
            if (menu.getTab3() != null) list.add(menu.getTab3());
            if (menu.getTab4() != null) list.add(menu.getTab4());
            if (menu.getTab5() != null) list.add(menu.getTab5());
        }
        return list;
    }

    @Override
    public List<MenuDTO> queryName(Integer mid) {
        List<Menu> list = list(new QueryWrapper<Menu>()
                .eq("menu_merachatId", mid));
        List<MenuDTO> menuDTOList=new ArrayList<>();
        list.forEach(menu -> {
            MenuDTO menuDTO=new MenuDTO();
            BeanUtils.copyProperties(menu,menuDTO);
            menuDTOList.add(menuDTO);
        });
        return menuDTOList;
    }
}
